package com.study.daily.algozuo.y2021.m12.day1202;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * findRelativeRanks
 *
 * @author Tom on 2021/12/2
 */
public class Code01_RelativeRanks {
    public static void main(String[] args) {
        Code01_RelativeRanks cr = new Code01_RelativeRanks();
        int[] score = new int[]{10,3,8,9,4};
        String[] ans = cr.findRelativeRanks(score);
        for(String ele: ans){
            System.out.print(ele + "  ");
        }
    }
    public String[] findRelativeRanks(int[] score) {
        int N = score.length;
        String[] ans = new String[N];
        PriorityQueue<Node> pq = new PriorityQueue<Node>(N, new MyCompartor());
        for(int i = 0; i < score.length; i++){
            pq.add(new Node(i,score[i]));
        }
        if(pq.size() > 0){
            ans[pq.poll().position] = "Gold Medal";
        }
        if(pq.size() > 0){
            ans[pq.poll().position] = "Silver Medal";
        }
        if(pq.size() > 0){
            ans[pq.poll().position] = "Bronze Medal";
        }
        if(pq.size() > 0){
            int i = 3;
            while(pq.size() > 0){
                ans[pq.poll().position] = (i+1) + "";
                i++;
            }
        }
        return ans;
    }
    class Node{
        private int position;
        private int value;
        public Node(int position, int value){
            this.value = value;
            this.position = position;
        }
    }
    class MyCompartor implements Comparator<Node>{
        @Override
        public int compare(Node o1, Node o2) {
            return o2.value - o1.value;
        }
    }
}
